export const guardObj = <T extends object>(obj: T, key: keyof T, _default: any = {}) => {
    if (!obj[key]) {
        obj[key] = _default;
    }
    return obj[key];
}

export const safeAccess = (obj: object, path: string[]) => {
    let iter = obj;
    for (let i = 0; i < path.length; ++i) {
        if (iter === undefined || iter === null) {
            return obj;
        }
        iter = iter[path[i]];
    }
    return iter;
}